package cn.summit.log.service.impl;

import cn.summit.log.dto.LogInfoDTO;
import cn.summit.log.service.AccessLogService;
import lombok.extern.slf4j.Slf4j;

import java.time.Duration;

/**
 * @author summit
 * @since 2020/6/23 17:23
 */
@Slf4j
public class DefaultAccessLogServiceImpl implements AccessLogService {

    @Override
    public void doBefore(LogInfoDTO dto) {
        log.info("请求方法 {}", dto.getClassMethod());
        log.info("请求来源 {},方式:{},地址:{}", dto.getRequest().getRemoteAddr(), dto.getHttpMethod(),
            dto.getUri());
    }

    @Override
    public void doAfter(LogInfoDTO dto) {
        log.info("请求耗时 {}ms", Duration.between(dto.getStartTime(), dto.getEndTime()).toMillis());

    }
}
